<template>
	<view>
		<view>
			<view class="top-text">返佣列表</view>
		</view>
		<u-table>
			<u-tr>
				<u-th>id</u-th>
				<u-th>订单类型</u-th>
				<u-th>订单金额</u-th>
				<u-th>返佣金额</u-th>
				<u-th>返佣比例</u-th>
			</u-tr>
			<u-tr v-for="item in data">
				<u-td>{{item.id}}</u-td>
				<u-td v-if="item.type == 1">线上支付</u-td>
				<u-td v-else-if="item.type == 2">聚合支付</u-td>
				<u-td v-else="item.type">未知</u-td>
				<u-td>{{item.totalAmount}}</u-td>
				<u-td>{{item.commission}}</u-td>
				<u-td>{{item.commissionRate}}</u-td>
			</u-tr>
		</u-table>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				id : 0,
				offset : 1,
				limit : 20,
				maxOffset : 0,
				type : '',
				userInfo : [],
				data : []
			}
		},
		onLoad() {
			uni.showLoading({
				title:'加载中....'
			});
		 this.userInfo = uni.getStorageSync('userInfo');
		 this.getIncome(this.userInfo.id);
		},
		onReachBottom() {
			if(this.offset > this.maxOffset){
				uni.showToast({
					title:'到底部了',
					icon:'none'
				})
			}else{
				this.getIncome(this.userInfo.id)
			}
			
		},
		methods:{
			getIncome(id){
				let that = this;	
				this.$request.httpTokenRequest({
					url:'/admin/agent/getIncome',
					method:'POST',
					data:{
						agentID:id,
						type:that.type,
						offset:that.offset,
						limit:that.limit,
					}
				}).then(res => {
					if(res.data.code == 200){
						uni.hideLoading();
						that.data = that.data.concat(res.data.content.data);
						that.maxOffset =  Math.ceil(res.data.content.count/that.limit);
						that.offset += 1;
					}else{
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
							duration: 2000
						});
					}
				},error => {});
			}
		}
		
	}

</script>

<style>
	.top-text{
		text-align: center;
		line-height: 100rpx;
		font-size: 30rpx;
		font-weight: 600;
	}
</style>

